package com.irononetech.android.MultilevelListView;

import android.app.ExpandableListActivity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.irononetech.android.Application.Application;
import com.irononetech.android.formcomponent.FormObject;
import com.irononetech.android.formcomponent.view.VehicleDetailsActivity;
import com.irononetech.android.claimsonersa.R;

public class ExpList3_Van extends ExpandableListActivity
{

	Logger LOG = LoggerFactory.getLogger(ExpList3_Van.class);

	
    static final String listdesc[][][][] = 
	{
        { // grey
          {  // lightgray
            { "Van", "Front face panel" },
            { "Front buffer","" },
		    { "Front grill","" },
		    { "Dash board","" },
		    { "Front badge","" },
		    { "A/C blower","" },
		    { "A/C cooler","" },
		    { "Horn","" },
		    { "Front windscreen","" },
		    { "Front single windscreen beading","" },
		    { "L/H/S front buffer end","" },
		    { "R/H/S front buffer end","" },
		    { "R/H/S head lamp","" },
		    { "L/H/S head lamp","" },
		    { "R/H/S head lamp frame","" },
		    { "L/H/S head lamp frame","" },
		    { "R/H/S front signal lamp","" },
		    { "L/H/S front signal lamp","" },
		    { "R/H/S front parking lamp","" },
		    { "L/H/S front parking lamp","" },
		    { "A/C Condensers","" },
		    { "A/C Filter","" },
		    { "Air horn","" },
		    { "Front number plate","" },
		    { "Front number plate lamp","" },
		    { "Fog lamps","" }, 
		    { "Face panel","" },
		    { "R/H/S side mirror","" }, 
		    { "R/H/S Side mirror arm","" },
		    { "L/H/S side mirror","" },
		    { "L/H/S Side mirror arm","" }, 
		    { "L/H/S side ball mirror","" }, 
		    { "R/H/S wiper blade","" },
		    { "R/H/S wiper arm","" }, 
		    { "L/H/S wiper blade","" },
		    { "L/H/S wiper arm","" }, 
		    { "Center upper shell","" },
		    { "Center lower shell","" },
		    { "Trim package","" }, 
		    { "Face cut/nose cut/half cut","" }
          },
          {  // darkgray
            { "Van", "Right body panel" },
            { "R/H/S driver door","" },
  		    { "R/H/S cut glass","" },
  		    { "R/H/S fit glass","" },
  		    { "R/H/S rain gutter","" },
  		    { "R/H/S body molding","" },
  		    { "R/H/S door hinges","" },
  		    { "R/H/S front tire","" },
  		    { "R/H/S driver door","" },
  		    { "R/H/S Driver door glass","" },
  		    { "R/H/S Driver door glass beading","" },
  		    { "R/H/S Door hinges","" },
  		    { "R/H/S Cut glass","" },
  		    { "R/H/S Cut glass frames","" },
  		    { "R/H/S Fit glass","" },
  		    { "R/H/S Fit glass frames","" },
  		    { "R/H/S Cut glass beading","" },
  		    { "R/H/S Fit glass beading","" },
  		    { "R/H/S Rain gutter","" },
  		    { "R/H/S Body aluminum molding","" },
  		    { "R/H/S Body molding","" },
  		    { "R/H/S Front tire","" },
  		    { "R/H/S Front rim","" },
  		    { "R/H/S Rear tire outer","" },
  		    { "R/H/S Rear tire outer rim","" },
  		    { "R/H/S Rear tire inner","" },
  		    { "R/H/S Rear tire inner rim","" },
  		    { "R/H/S Mirror","" },
  		    { "R/H/S Front tire Wheel nuts","" },
  		    { "R/H/S Rear tire outer Wheel nuts","" },
  		    { "R/H/S Rear tire inner Wheel nuts","" },
  		    { "Rim cups (if available)","" },
  		    { "R/H/S center door","" },
  		    { "R/H/S center door glass","" },
  		    { "R/H/S center door glass beading","" },
  		    { "R/H/S center hinges","" },
  		    { "R/H/S Mudguard guard arch","" },
  		    { "R/H/S Mudguard arch cover","" },
  		    { "M R/H/S mudguard beading","" }
          },
          {  // darkgray
            { "Van", "Left body panel" },
            { "L/H/S front door","" },
		    { "L/H/S front board","" },
		    { "L/H/S cut glasses","" },
		    { "L/H/S foot board","" },
		    { "L/H/S fit glasses","" },
		    { "L/H/S body rubber","" },
		    { "L/H/S rear tire inner","" },
		    { "L/H/S Front door glass","" },
		    { "L/H/S Front door glass beading","" },
		    { "L/H/S Front door rubber flap","" },
		    { "L/H/S Front door winder","" },
		    { "L/H/S Foot board lamp","" },
		    { "L/H/S Front rain gutter","" },
		    { "L/H/S Body aluminum molding","" },
		    { "L/H/S Body rubber molding","" },
		    { "L/H/S Cut glasses frames","" },
		    { "L/H/S Fit glasses frames","" },
		    { "L/H/S Cut glass beading","" },
		    { "L/H/S Fit glasses beading","" },
		    { "L/H/S center foot board","" },
		    { "L/H/S center foot board lamp","" },
		    { "L/H/S center foot board door","" },
		    { "L/H/S center foot board door glass","" },
		    { "L/H/S center foot board door beading","" },
		    { "L/H/S center foot board door rubber flap","" },
		    { "L/H/S center door","" },
		    { "L/H/S center door glass","" },
		    { "L/H/S center door glass beading","" },
		    { "L/H/S center hinges","" },
		    { "L/H/S Rear rain gutter","" },
		    { "L/H/S Front tire","" },
		    { "L/H/S Front tire rim","" },
		    { "L/H/S Rear tire outer","" },
		    { "L/H/S Rear tire outer rim","" },
		    { "L/H/S Rear tire inner rim","" },
		    { "L/H/S Front tire Wheel nuts","" },
		    { "L/H/S Rear tire outer Wheel nuts","" },
		    { "L/H/S Rear tire inner Wheel nuts","" },
		    { "L/H/S Rim cups (if available)","" }
            },
            {  // darkgray
            { "Van", "Rear side" },
            { "Rear buffer","" },
            { "Rear windscreen","" },
            { "R/H/S Rear windscreen","" },
            { "L/H/S Rear windscreen","" },
            { "R/H/S Rear windscreen beading","" }, 
            { "R/H/S Rear windscreen beading","" },
            { "Rear windscreen beading","" }, 
            { "Rear name board box glass","" },
            { "Rear name board box glass beading","" },
            { "Rear name board box glass lamp","" },
            { "L/H/S tail light rear","" },
            { "R/H/S Rear tail light","" },
            { "L/H/S Rear tail light","" },
            { "R/H/S rear parking lamp","" },
            { "L/H/S rear parking lamp","" },
            { "R/H/S rear buffer end","" },
            { "L/H/S rear buffer end","" },
            { "Dickey door","" },
            { "Dickey door lights","" },
            { "Dickey door garnish","" },
            { "Dickey door locks","" },
            { "Dickey door handles","" },
            { "Dickey door ladder","" },
            { "Dickey door beadings","" },
            { "Rear umber plate","" },
            { "Rear umber plate lamp","" },
            { "Back body aluminum molding","" },
            { "Back body rubber beading","" }, 
            { "Rear windscreen mirror","" }, 
            { "Wiper arm","" },
            { "Wiper blade","" }
            },
            {
          	  { "Van", "Engine compartment and components" },
          	  { "Diesel, petrol engine (gasoline engine)","" },
          	  { "Accessory belt","" },
          	  { "Air duct","" },
          	  { "Air intake housing","" },
          	  { "Air intake manifold","" },
          	  { "Camshaft","" },
          	  { "Camshaft bearing","" },
          	  { "Camshaft fastener","" },
          	  { "Camshaft follower","" },
          	  { "Camshaft locking plate","" },
          	  { "Camshaft pushrod","" },
          	  { "Camshaft spacer ring","" },
          	  { "Connecting rod","" },
          	  { "Connecting rod bearing","" },
          	  { "Connecting rod bolt","" },
          	  { "Connecting rod washer","" },
          	  { "Crank case","" },
          	  { "Crank pulley","" },
          	  { "Crankshaft","" },
          	  { "Crankshaft oil seal","" },
          	  { "Cylinder head","" },
          	  { "Cylinder head cover","" },
          	  { "Other cylinder head cover parts","" },
          	  { "Cylinder head gasket","" },
          	  { "Distributor","" },
          	  { "Distributor cap","" }, 
          	  { "Drive belt","" },
          	  { "Engine block","" }, 
          	  { "Engine block parts","" },
          	  { "Engine cradle","" },
          	  { "Engine shake damper and vibration absorber","" },
          	  { "Engine valve","" },
          	  { "Fan belt","" },
          	  { "Gudgeon pin (wrist pin)","" },
          	  { "Harmonic balancer","" },
          	  { "Heater","" },
          	  { "Mounting bolt","" },
          	  { "Piston pin and crank pin","" },
          	  { "Piston pin bush","" },
          	  { "Piston ring and circlip","" },
          	  { "Piston valve","" }, 
          	  { "Poppet valve","" }, 
          	  { "PCV valve (positive crankcase ventilation valve)","" },  
          	  { "Pulley part","" }, 
          	  { "Rocker arm","" }, 
          	  { "Rocker cover Starter motor","" }, 
          	  { "Rocker cover Starter pinion","" }, 
          	  { "Rocker cover Starter ring","" }, 
          	  { "Turbocharger and supercharger","" },  
          	  { "Tappet","" },
          	  { "Timing tape ","" }, 
          	  { "Valve cover","" },
          	  { "Valve housing","" }, 
          	  { "Valve spring","" },
          	  { "Valve stem seal","" }, 
          	  { "Water pump pulley","" }
            },
            {
          	  { "Van", "Engine cooling system" },
          	  { "Air blower","" },
          	  { "Coolant hose cooling fan","" }, 
          	  { "Fan blade","" },
          	  { "Fan clutch","" },
          	  { "Radiator bolt","" },
          	  { "Radiator shroud","" },
          	  { "Radiator gasket","" },
          	  { "Radiator pressure cap","" }, 
          	  { "Water neck","" },
          	  { "Water neck o-ring","" }, 
          	  { "Water pipe","" },
          	  { "Water pump","" },
          	  { "Water pump gasket","" }, 
          	  { "Water tank","" },
          	  { "Thermostat","" }
            },
            {          
          	  { "Van", "Engine oil system" },
          	  { "Oil filter","" }, 
          	  { "Oil gasket","" }, 
          	  { "Oil pan","" },
          	  { "Oil pipe","" }, 
          	  { "Oil pump","" }, 
          	  { "Oil strainer","" }
            },
            {
          	  { "Van","Exhaust system" },
          	  { "Catalytic converter","" },
          	  { "Exhaust clamp and bracket","" }, 
          	  { "Exhaust flange gasket","" },
          	  { "Exhaust gasket","" }, 
          	  { "Exhaust manifold","" }, 
          	  { "Exhaust manifold gasket","" }, 
          	  { "Exhaust pipe","" }, 
          	  { "Heat shield","" }, 
          	  { "Heat sleeving and tape","" }, 
          	  { "Muffler (silencer)","" }
            },
            {
          	  { "Van", "Fuel supply system" },
          	  { "Air filter","" },
          	  { "Carburetor","" },
          	  { "Carburetor parts","" },
          	  { "Choke cable","" },
          	  { "EGR valve","" },
          	  { "Fuel cap","" },
          	  { "Fuel cell","" },
          	  { "Fuel cell component","" },
          	  { "Fuel cooler","" },
          	  { "Fuel distributor","" },
          	  { "Fuel filter","" },
          	  { "Fuel filter seal","" },
          	  { "Fuel injector","" },
          	  { "Fuel injector nozzle","" },
          	  { "Fuel pump","" },
          	  { "Fuel pump gasket","" },
          	  { "Fuel pressure regulator","" },
          	  { "Fuel rail","" },
          	  { "Fuel tank","" },
          	  { "Fuel tank cover","" },
          	  { "Fuel water separator","" },
          	  { "Intake manifold","" },
          	  { "Intake manifold gasket","" },
          	  { "LPG (Liquefied petroleum gas) system assembly","" }, 
          	  { "Throttle body","" },
          	  { "Universal joint","" }
            },
            {
          	  { "Van","Other miscellaneous parts" },
          	  { "Adhesive tape and foil","" },  
          	  { "Bolt cap","" },
          	  { "License plate bracket","" }, 
          	  { "Speedometer cable","" },
          	  { "Cotter pin","" }, 
          	  { "Decal","" }, 
          	  { "Dashboard","" }, 
          	  { "Center console","" }, 
          	  { "Glove compartment","" }, 
          	  { "Drag link","" }, 
          	  { "Dynamic seal","" }, 
          	  { "Fastener","" }, 
          	  { "Gasket: Flat, molded, profiled","" }, 
          	  { "Hood and trunk release cable","" }, 
          	  { "Horn and trumpet horn","" }, 
          	  { "Injection-molded parts","" }, 
          	  { "Instrument cluster","" }, 
          	  { "Label","" }, 
          	  { "Mirror","" }, 
          	  { "Mount and mounting","" }, 
          	  { "Name plate","" }, 
          	  { "Flange nut","" }, 
          	  { "Hex nut","" }, 
          	  { "O-ring","" }, 
          	  { "Paint","" },
          	  { "Rivet","" },
          	  { "Rubber (extruded and molded)","" }, 
          	  { "Screw","" }, 
          	  { "Shim","" },
          	  { "Sun visor","" }
            },
        }
	};

  FormObject fo;  
  static boolean booleanlistVan[][][][];
  static boolean booleanprelistVan[][][][];
  Button back;
  EditText otherfield;
    
  
  	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle){
        try {
			super.onCreate(icicle);
			LOG.debug("ENTRY onCreate");
			setContentView(R.layout.multilevel_expandable_list_main);
			fo=com.irononetech.android.Application.Application.getFormObjectInstance();
			back = (Button)findViewById(R.id.button2);
			otherfield = (EditText)findViewById(R.id.damagedItemsOtherField);
			
			if(fo.getisPreSelected())  //PRE
			{
				otherfield.setText(fo.getpredamagedItemsOtherField());
				booleanprelistVan = fo.getBooleanprelistVan();
			    colorExpListAdapter=
					new ColorExpListAdapterVan(
						this,
			            getExpandableListView(),
			            listdesc
					);
				setListAdapter( colorExpListAdapter );
				
				back.setBackgroundDrawable(getResources()
						.getDrawable(R.drawable.back_button_xml));
			}
			else {
			otherfield.setText(fo.getdamagedItemsOtherField());
			booleanlistVan = fo.getBooleanlistVan();
			colorExpListAdapter=
				new ColorExpListAdapterVan(
					this,
			        getExpandableListView(),
			        listdesc
				);
			setListAdapter( colorExpListAdapter );
			
			back.setBackgroundDrawable(getResources()
					.getDrawable(R.drawable.cancel_button_xml));
			}
			if(!fo.isEditable()){
				editDisable();
			}
			LOG.debug("SUCCESS onCreate");
		} catch (NotFoundException e) {
			 LOG.error("onCreate:10327");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("onCreate:10328");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
    }

    public void editDisable() {
    	try {
			otherfield.setFocusable(false);
			
			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources()
						.getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources()
						.getDrawable(R.drawable.back_button_xml));
			}
		} catch (NotFoundException e) {
			 LOG.error("editEnable:10329");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("editEnable:10330");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
    }
    
    public void editEnable() {
    	try {
			otherfield.setFocusable(true);
			
			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources()
						.getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources()
						.getDrawable(R.drawable.cancel_button_xml));
			}
		} catch (NotFoundException e) {
			 LOG.error("editEnable:10331");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			 LOG.error("editEnable:10332");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}

    public void multilevel_ok_click(View v){
    	try {
			if(fo.getisPreSelected())  //PRE
			{
			  fo.setBooleanprelistVan(booleanprelistVan);
			  fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
			}
			else {
				fo.setBooleanlistVan(booleanlistVan);
				fo.setdamagedItemsOtherField(otherfield.getText().toString().trim());
			}
			  
			  Intent mIntent = new Intent(ExpList3_Van.this,
						VehicleDetailsActivity.class);
				mIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				startActivity(mIntent);
				finish();
		} catch (Exception e) {
			 LOG.error("editEnable:10333");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
    }
    
public void multilevel_back_button(View v){
	try {
		if (fo.isEditable()) {
			int p1 = Application.get4DArrSizeSec1();
			int p2 = Application.get4DArrSizeSec2();
			int p3 = Application.get4DArrSizeSec3();
			int p4 = Application.get4DArrSizeSec4();
			boolean[][][][] a = new boolean[p1][p2][p3][p4];
			if(!fo.getisPreSelected()) {
				  //Damaged Items
				  fo.setisVehicleShow(true);
				  fo.setdamagedItemsOtherField("");
				  fo.setpredamagedItemsOtherField("");
				  fo.setBooleanlistVan(a);
				  fo.setBooleanprelistVan(a);
				}
			else{
				//Pre Damaged Items
				fo.setBooleanprelistVan(a);
				fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
			}
		}
		finish();
	} catch (Exception e) {
		 LOG.error("editEnable:10334");
		   if(e != null){
			LOG.error("Message: " + e.getMessage());
			LOG.error("StackTrace: " + e.getStackTrace());
		  }
	}
    }

    private ColorExpListAdapterVan colorExpListAdapter;
}
